import pymysql

db = pymysql.connect(host='localhost', user='root',
                     password='12345678', database='mrsoft', charset='utf8')

cursor = db.cursor()

data = [
      ('零基础学Python', 'Python', '79.8', '2018-5-20'),
      ('Python从入门到精通', 'Python', '69.9', '2018-6-18'),
      ('零基础学PHP', 'PHP', '69.8', '2017-5-21'),
      ('PHP项目开发实战入门', 'PHP', '79.8', '2016-5-21'),
      ('零基础学Java', 'Java', '69.8', '2017-5-21'),
  ]

try: 
    stmt = "INSERT INTO books (name, category, price, publish_time) VALUES (%s, %s, %s, %s)"
    cursor.executemany(stmt, data)
    db.commit()
except ValueError as e:
    print(e)
    db.rollback()

db.close()
